<template>
	<view class="pics">
		<scroll-view class="left" scroll-y>
			<view @click="leftClickHandle(index,item.id)" :class="active===index?'active':''" v-for="(item,index) in cates" :key="item.id">{{item.title}}</view>
			
		</scroll-view>
		<scroll-view class="right" scroll-y>
			<view class="item" v-for="item in rightData" :key="item.id">
				<image @click="yulan(item.img_url)" :src="item.img_url"></image>
				<text>{{item.title}}</text>
			</view>
			<view v-if="rightData.length===0" class="nodata">暂无数据</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates:[],
				active:0,
				rightData:[]
			}
		},
		methods: {
			async getPicsCate(){
				const res =await this.$myRequest({
					url:'/api/getimgcategory'
				})
				// console.log(res);
				this.cates=res.data.message;
				this.leftClickHandle(0,this.cates[0].id);
			},
			async leftClickHandle(index,id){
				this.active=index;
				const res=await this.$myRequest({
					url:"/api/getimages/"+id
				})
				// console.log(res);
				this.rightData=res.data.message;
			},
			yulan(current){
				const urls=this.rightData.map(item=>{
					return item.img_url;
				})
				uni.previewImage({
					current,
					urls
				})
			}
		},
		onLoad(){
			this.getPicsCate();
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.pics{
		display: flex;
		height: 100%;
		.left{
			width: 200rpx;
			height: 100%;
			border-right: 1px solid #eee;
			view{
				height: 120rpx;
				line-height: 120rpx;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top: 1px solid #eee;
			}
			.active{
				background-color: $shop-color;
				color: #FFFFFF;
			}
		}
		.right{
			width: 530rpx;
			height: 100%;
			margin: 10rpx auto;
			.item{
				image{
					width: 530rpx;
					height: 530rpx;
					border-radius: 5px;
				}
				text{
					font-size: 28rpx;
					line-height: 55rpx;
				}
			}
			.nodata{
				font-size: 30rpx;
			}
		}
	}
</style>
